package cn.com.vrv.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.com.vrv.common.AbstractController;
import cn.com.vrv.common.Constant;
import cn.com.vrv.service.RecognitionTaskService;

/**
 * 登录控制器
 * 
 * @author 赵炎
 * @version [V1.00, 2017年11月21日]
 * @see [相关类/方法]
 * @since V1.00
 */
@Controller
public class LoginController extends AbstractController
{
    
    @Value("${login.username}")
    private String username;
    
    @Value("${login.password}")
    private String password;
    
    
    @RequestMapping(value = "/")
    public String index()
    {
        return "index";
    }
    
    /**
     * 用户登录
     * 
     * @param request
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public String login(Model model,HttpServletRequest request)
    {
        // 页面参数
        String userName = request.getParameter("username");
        String passWord = request.getParameter("password");
        if (username.equals(userName) && password.equals(passWord))
        {
            log.info("验证成功:{}", userName);
            request.getSession().setAttribute(Constant.SESSION_USER_KEY, username);
        }
        else
        {
            log.error("登录失败");
            return "error";
        }
        
        return "redirect:task/list";
    }
    
    /**
     * 登出
     * 
     * @param request
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "logout")
    public String logout(HttpServletRequest request)
    {
        request.getSession().removeAttribute(Constant.SESSION_USER_KEY);
        return "redirect:/";
    }
}
